Haad Khan
12th March 2015
This presentation is about visualizing data with R
-Adapted from Dawn Koffman Office of Population Research Princeton University
ggplot2 provides two ways to produce plot objects:
very easy to produce basic graphs
ggplot() grammar of graphics
has a steeper learning curve but extremely powerful
data: in ggplot2, data must be stored as an R data frame
coordinate system: decribes 2-D space that data is projected onto
geoms: describe type of geometric objects that represent data
aesthetics: describe visual characteristics that represent data
scales: for each aesthetic, describe how visual characteristic is converted to display values
stats: describe statistical transformations that typically summarize data
facets: describe how data is split into subsets and displayed as multiple small graphs
#install.packages("ggplot2")
library(ggplot2)
ggplot(diamonds, aes(x=carat, y=price)) + geom_point()
ggplot(pressure, aes(x=temperature, y=pressure)) + geom_line()
ggplot(diamonds,aes(x=carat, y=price))+ geom_point()+ stat_smooth()
ggplot(diamonds,aes(x=carat, y=price))+ geom_point()+ stat_smooth()+xlim(0.2,1)
ggplot(diamonds,aes(x=carat, y=price))+ geom_jitter()+ stat_smooth()+xlim(0.2,1)
ggplot(diamonds,aes(x=carat, y=price))+ geom_polygon()+ stat_smooth()+xlim(0.2,1)
ggplot(diamonds,aes(x=carat, y=price))+ geom_text(label = '@')+ stat_smooth()+xlim(0.2,1)